<template>
    <div>
        <div class="crumbs">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item> <i class="el-icon-lx-cascades"></i> 订单管理 </el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <div class="container">
            <div class="handle-box">
                <el-form :inline="true" class="demo-form-inline">
                    <el-form-item label="订单号">
                        <el-input v-model="query.keyword" placeholder="请输入订单号"></el-input>
                    </el-form-item>
                    <el-form-item label="下单时间">
                        <el-date-picker
                            v-model="orderDate"
                            type="datetimerange"
                            range-separator="至"
                            start-placeholder="开始日期"
                            end-placeholder="结束日期"
                            value-format="yyyy-MM-dd HH:mm:ss"
                            @change="orderTime"
                        >
                        </el-date-picker>
                    </el-form-item>
                    <el-form-item label="订单状态">
                        <el-select v-model="query.status">
                            <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value"> </el-option>
                        </el-select>
                    </el-form-item>

                    <el-form-item>
                        <el-button type="primary" @click="handleSearch">查询</el-button>
                        <el-button @click="reset">重置</el-button>
                    </el-form-item>
                </el-form>
            </div>
            <el-table
                :data="tableData"
                class="table"
                ref="multipleTable"
                header-cell-class-name="table-header"
                :expand-row-keys="expends"
                :row-key="getRowKeys"
            >
                <el-table-column type="expand">
                    <template slot-scope="scope">
                        <el-form label-position="top" inline class="demo-table-expand">
                            <el-form-item label="订单号：">
                                <span>{{scope.row.order_no}}</span>
                            </el-form-item>
                            <el-form-item label="支付时间：">
                                <span>{{ scope.row.paid_time }}</span>
                            </el-form-item>
                            <el-form-item label="用户：">
                                <span>{{ scope.row.nickname }}</span>
                            </el-form-item>
                            <el-form-item label="手机号：">
                                <span>{{ scope.row.phone }}</span>
                            </el-form-item>
                        </el-form>
                    </template>
                </el-table-column>
                <el-table-column label="订单信息" width="300">
                    <template slot-scope="scope">
                        <div class="course-info-wrapper">
                            <div class="img-wrapper">
                                <!-- <img :src="scope.row.product.cover" alt="" class="info-image" /> -->
                                <img :src="scope.row.product.cover" @error="tabErrorPicture(scope.row.id)" alt="" class="info-image" v-if="scope.row.product.cover" />
                                <img :src="errorProduct" alt="" class="info-image" v-else />
                            </div>
                            <div class="info-detail">
                                <div class="title">
                                    <span>{{ scope.row.product.title }}</span>
                                </div>

                                <span class="product_type">{{ scope.row.product_type }}</span>
                            </div>
                        </div>
                    </template>
                </el-table-column>
                <el-table-column label="单价">
                    <template slot-scope="scope">
                        <span class="red">{{ '¥ ' + scope.row.product.price }}</span>
                    </template>
                </el-table-column>
                <el-table-column label="应支付金额">
                    <template slot-scope="scope">
                        <span class="red">{{ '¥ ' + scope.row.paid_fee }}</span>
                    </template>
                </el-table-column>
                <el-table-column prop="create_time" label="下单时间"></el-table-column>
                <el-table-column label="支付状态">
                    <template slot-scope="scope">
                        <span v-if="scope.row.paid==0" style="color: red">待退款</span>
                        <span v-if="scope.row.paid==1" style="color: #38b03f">退款完成</span>
                    </template>
                </el-table-column>

                <el-table-column label="操作" width="180" align="center" fixed="right">
                    <template slot-scope="scope">
                        <el-button @click="detail(scope.row.id, scope.row.order_no, scope.row.product.title)" type="primary" size="mini">详情</el-button>
                        <!-- <el-button @click="edit(scope.row.id, scope.row)" type="success" size="mini">编辑</el-button> -->
                        <el-button v-if="scope.row.paid == 1" @click="deleteRow(scope.row.id, scope.$index)" type="danger" size="mini">删除</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <div class="pagination">
                <el-pagination
                    background
                    layout="total, prev, pager, next"
                    :current-page="query.page"
                    :page-size="query.rows"
                    :total="pageTotal"
                    @current-change="handlePageChange"
                ></el-pagination>
            </div>
        </div>

        
        
    </div>
</template>

<script>
import { refundListData, delRefundData } from '../../api/index';
export default {
    // name: 'basetable',
    data() {
        return {
            query: {
                page: 1,
                rows: 4,
                keyword: '',
                start_time: '',
                end_time: '',
                status: ''
            },
            options: [
                {
                    value: '0',
                    label: '待退款'
                },
                {
                    value: '1',
                    label: '退款完成'
                }
            ],
            expends: [],
            orderDate: [],
            tableData: [],
            pageTotal: 0,
            errorProduct: require('@/assets/img/noProduct.jpg'),
        };
    },
    created() {
        this.getData();
    },
    methods: {
        tabErrorPicture(id){    // 表格图文封面默认展示图
            let i = this.tableData.findIndex(v => v.id == id);
			this.tableData[i].product.cover = this.errorProduct;
        },
        getData() {
            refundListData(this.query).then((res) => {
                this.tableData = res.data.list;
                this.pageTotal = res.data.count;
                let Id = this.tableData.map((item) => item.id);
                this.expends = Id;
            });
        },

        getRowKeys(row) {
            return row.id;
        },
        orderTime(val) {
            this.query.start_time = val[0];
            this.query.end_time = val[1];
        },
        // 查询
        handleSearch() {
            this.$set(this.query);
            this.getData();
        },
        reset() {
            this.query = {};
            this.orderDate = [];
        },
        // 详情
        detail(id, order_no, title) {
            this.$router.push({ path: '/order_manage/refund_detail', query: { id, order_no, title } });
        },
        // 删除
         deleteRow(id, index) {
            // 二次确认删除
            this.$confirm('确定要删除吗？', '提示', {
                type: 'warning'
            }).then(() => {
                delRefundData({ id: id }).then((res) => {
                    if (res.code == 1) {
                        this.$message.success('删除成功');
                        this.tableData.splice(index, 1);
                        setTimeout(() => {
                            location.reload();
                        }, 200);
                    }
                });
            });
        },
        // 分页
        handlePageChange(val) {
            this.$set(this.query, 'page', val);
            this.getData();
        }
    }
};
</script>

<style scoped>
.table {
    width: 100%;
    font-size: 14px;
}
.course-info-wrapper {
    display: flex;
    align-items: center;
    width: 100%;
    height: 64px;
    padding-right: 58px;
    text-align: left;
    cursor: pointer;
}
.course-info-wrapper .img-wrapper {
    position: relative;
}
.course-info-wrapper .info-image {
    height: 64px;
    width: 80px;
    border-radius: 4px;
}

.course-info-wrapper .info-detail {
    line-height: 1.5;
    height: 100%;
    margin-left: 8px;
}
.course-info-wrapper .info-detail .title {
    max-width: 100%;
    height: 44px;
    font-size: 14px;
    font-weight: 400;
    color: #333333;
    line-height: 22px;
    overflow: hidden;
    text-overflow: ellipsis;
    word-wrap: break-word;
    white-space: pre-wrap;
}
.course-info-wrapper .info-detail .product_type {
    display: inline-block;
    padding: 0 5px;
    color: #fff;
    background: rgba(0, 0, 0, 0.5);
    border-radius: 3px;
}
.red {
    color: red;
}
</style>

<style>
.demo-table-expand {
    height: 20px;
}
.demo-table-expand label {
    /* width: 90px; */
    color: #99a9bf;
}
.demo-table-expand .el-form-item {
    margin-right: 0;
    margin-bottom: 0;
    width: 20%;
}
.el-table__expand-column {
    pointer-events: none;
}
.el-table__expand-column .el-icon {
    visibility: hidden;
}
.el-form--inline.el-form--label-top .el-form-item__content {
    display: inline-block;
    line-height: 0;
}
.demo-table-expand .el-form-item__label {
    line-height: 20px;
}
.demo-table-expand span {
    line-height: 20px;
}
.el-table__expanded-cell {
    background: #f7f9fb;
}
.el-table td.el-table__cell {
    border: none;
}
.el-table__expanded-cell {
    border-bottom: 1px solid #ebeef5 !important;
}
.el-table th {
    background-color: #f1f1f1 !important;
}
</style>

